<?php



require ROOT_PATH.'/Helper/base_abstract.php';

abstract class front_base_abstract extends base_abstract
{
    function __construct($controller)
    {
        parent::__construct($controller);

        $this->queue = array();

        if (isset($_COOKIE['queue'])) {
            $this->queue = array_filter(array_unique(explode(',', $_COOKIE['queue'])));
        }

        if (!empty($_SESSION['user'])) {
            $count = count(_model()->getList("SELECT DISTINCT asset_id FROM download_history WHERE user_id = {$_SESSION['user']['id']} AND asset_id NOT IN(SELECT asset_id FROM vote_history WHERE user_id = {$_SESSION['user']['id']})"));
            $this->download_vote_num = $count;
            $this->view->assign('download_vote_num', $count);
        }

        $this->view->assign('queue_num', count($this->queue));
    }
    
    function https_redirect()
    {
        $https = Config::get('htts_on');
        if (!$https) {
           return ;
        }
        if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'){
            return ;
        }
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            return ;
        }
        if (!isset($_SERVER['HTTPS'])) {
            header('Location: ' . 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
        }
    }

    function msg($msg, $jumpurl='', $t = 3) {
       if ($jumpurl) {
            $jumpurl = htmlspecialchars($jumpurl);
            if (substr($jumpurl, 0, 4) != 'http') {
                if ($jumpurl{0} != '/') {
                    $jumpurl = '/'.$jumpurl;
                }
                $jumpurl = SITE_URL.$jumpurl;
            }
            $ifjump = "<META HTTP-EQUIV='Refresh' CONTENT='$t; URL=$jumpurl'>";
            $this->view->assign('jumpurl', $jumpurl);
            $this->view->assign('ifjump', $ifjump);
        }

        $this->view->assign('msg', $msg);
        $this->view->display('front/business_succ.html');
        exit;
    }
}


?>